temp = ['1', '2', '3', '4', '5']
def check(x):
    a = str(x)
    flag = True
    
    for i in range(0, len(a)):
        if a[i] not in temp:
            flag = False
    for i in range(0, len(a) - 1):
        if a[i] == '1':
            if a[i + 1] != '3' and a[i + 1] != '5':
                flag = False
        if a[i] == '2':
            if a[i + 1] != '3' and a[i + 1] != '4':
                flag = False
        if a[i] == '3':
            if a[i + 1] != '1' and a[i + 1] != '4':
                flag = False
        if a[i] == '4':
            if a[i + 1] != '5':
                flag = False
    return flag

ans = 1

n = int(input())

while True:
    if check(ans * n):
        print(ans * n)
        break
    ans = ans + 1